<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:33:"./themes/admin/dp\course_add.html";i:1742883762;s:39:"D:\phpcode\syzth\themes\admin\base.html";i:1741049647;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><?php echo $setup['title']; ?></title>
    <meta content="<?php echo $setup['keywords']; ?>" name="keywords" />
    <meta content="<?php echo $setup['description']; ?>" name="description" />
    <?php if($setup['ico'] != null): ?><link rel="shortcut icon" type="image/x-icon"  href="/public/uploads/<?php echo $setup['ico']; ?>"/><?php endif; ?>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
    <!--CSS引用-->
    
    <!--页面CSS-->
    <!--[if lt IE 9]>
    <script src="/public/static/js/html5shiv.min.js"></script>
    <script src="/public/static/js/respond.min.js"></script>
    <![endif]-->
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li><a href="<?php echo url('admin/dp/course'); ?>">课程管理</a></li>
                <li class="layui-this">添加课程</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="<?php echo url('admin/dp/save_course'); ?>" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">课程名</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" required lay-verify="required" placeholder="请输入课程名" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">课程分类</label>
                            <div class="layui-input-block">
                                <select name="category_id" lay-verify="required">
                                    <option value="">请选择分类</option>
                                    <?php if(is_array($category_list) || $category_list instanceof \think\Collection || $category_list instanceof \think\Paginator): if( count($category_list)==0 ) : echo "" ;else: foreach($category_list as $key=>$cat): ?>
                                        <optgroup label="<?php echo $cat['name']; ?>">
                                            <?php if(is_array($cat['children']) || $cat['children'] instanceof \think\Collection || $cat['children'] instanceof \think\Paginator): if( count($cat['children'])==0 ) : echo "" ;else: foreach($cat['children'] as $key=>$sub): ?>
                                            <option value="<?php echo $sub['id']; ?>"><?php echo $sub['name']; ?></option>
                                            <?php endforeach; endif; else: echo "" ;endif; ?>
                                        </optgroup>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">课程专家</label>
                            <div class="layui-input-block">
                                <select name="expert_id" lay-verify="required">
                                    <option value="">请选择专家</option>
                                    <?php if(is_array($expert_list) || $expert_list instanceof \think\Collection || $expert_list instanceof \think\Paginator): if( count($expert_list)==0 ) : echo "" ;else: foreach($expert_list as $key=>$expert): ?>
                                    <option value="<?php echo $expert['id']; ?>"><?php echo $expert['name']; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">课程时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="course_time" id="course_time" required lay-verify="required" placeholder="请选择课程时间" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">上课地点</label>
                            <div class="layui-input-block">
                                <input type="text" name="location" required lay-verify="required" placeholder="请输入上课地点" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">最大人数</label>
                            <div class="layui-input-block">
                                <input type="number" name="max_number" required lay-verify="required|number" placeholder="请输入最大预约人数" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">标题图片</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title_image" id="title_image" placeholder="请上传标题图片" class="layui-input">
                                <img id="preview_title" src="" style="margin-top:10px;max-height:100px;display:none;">
                            </div>
                            <button type="button" class="layui-btn" id="upload_title_image">上传图片</button>
                        </div>
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label">海报图片</label>
                            <div class="layui-input-inline">
                                <input type="text" name="poster_image" id="poster_image" placeholder="请上传海报图片" class="layui-input">
                                <img id="preview_poster" src="" style="margin-top:10px;max-height:100px;display:none;">
                            </div>
                            <button type="button" class="layui-btn" id="upload_poster_image">上传图片</button>
                        </div>
                        

                        <div class="layui-form-item">
                            <label class="layui-form-label">课程介绍</label>
                            <div class="layui-input-block">
                                <textarea name="desc" placeholder="请输入课程介绍" class="layui-textarea"></textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="submitCourse">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!--页面-->

<!--JS引用-->
<script src="/public/static/js/jquery.min.js"></script>
<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: "lib/index" //主入口模块
    }).use('index');
</script>

<script>
    layui.use(['form', 'laydate', 'upload'], function(){
        var form = layui.form, laydate = layui.laydate, upload = layui.upload;

        // 时间选择器
        laydate.render({
            elem: '#course_time',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss'
        });

        // 标题图片上传
        upload.render({
    elem: '#upload_title_image',
    url: '/index/index/upload',
    field: 'file',
    done: function(res){
        if(res.code === 1){
            const url = '/public/' + res.data.url;
            $('#title_image').val(url);
            $('#preview_title').attr('src', url).show();
            layer.msg('上传成功');
        } else {
            layer.msg('上传失败');
        }
    }
});

// 海报图片上传 + 预览
upload.render({
    elem: '#upload_poster_image',
    url: '/index/index/upload',
    field: 'file',
    done: function(res){
        if(res.code === 1){
            const url = '/public/' + res.data.url;
            $('#poster_image').val(url);
            $('#preview_poster').attr('src', url).show();
            layer.msg('上传成功');
        } else {
            layer.msg('上传失败');
        }
    }
});

        // 提交表单
        form.on('submit(submitCourse)', function(data){
            $.ajax({
                url: data.form.action,
                type: data.form.method,
                data: $(data.form).serialize(),
                success: function(info){
                    if(info.code === 1){
                        setTimeout(function(){
                            window.location.href = "<?php echo url('admin/dp/course'); ?>";
                        }, 1000);
                    }
                    layer.msg(info.msg);
                }
            });
            return false;
        });
    });
</script>

<!--页面JS脚本-->
</body>
</html>

